﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Azad;
using Azad.BCL;
using System.Web.UI.HtmlControls;
using BCL.Entity;
using NazSoft.Framework;

public partial class UserControl_NewWeekSlider : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

        Application["images"] = @"/images/";

        var collection = Request.QueryString;
        String mn = collection["mn"] ?? "taza-tareen"; // menu name
        string mp = collection["mp"];
        bool preview = Convert.ToBoolean(collection["preview"]);

        if (Page.IsPostBack == false)
        {
            SilverlightService silverlightService = new SilverlightService();
            var today = DateTimeUtilities.GetDateFromQueryString(collection);

            var logoInfo = silverlightService.GetByCurrentId(today, preview);
            var details = logoInfo.Detail.Where(x => x.MenuId == 11).FirstOrDefault();

            if (details != null)
            {

                btnNext.ImageUrl = Convert.ToString(Application["images"]) + "right_aero.gif";
                btnPrevious.ImageUrl = Convert.ToString(Application["images"]) + "left_aero.gif";
                imgLoading.Src = Convert.ToString(Application["images"]) + "loadingImages.gif";

                SlidingEffect1.ItemDatabound += new ItemDataBound(SlidingEffect1_itemDatabound);


                if (Convert.ToBoolean(SessionHandler.GetItem("EnabledAjax")) == false)
                {
                    int skip = Convert.ToInt32(Session["SkipPage"]) * 1;
                    int pageNo = (Convert.ToInt32(Session["PageNo"]) + 1) * 1;
                    //if (Convert.ToInt32(Session["PageNo"]) == 0)
                    SlidingEffect1.DataSource = details.DetailToDetail;//.OrderBy(f => f.OrderNo).Skip(skip).Take(1);
                    //else
                    //    SlidingEffect1.DataSource = details.DetailToDetail.OrderBy(f => f.OrderNo).Skip(skip).Take(pageNo);
                }

                SlidingEffect1.ProgressBarId = UpdateProgressBar.ID;

                SlidingEffect1.PageSize = 1;

                SlidingEffect1.GroupItemCount = 50;
                SlidingEffect1.IsGroupTemplate = true;
                SlidingEffect1.TotalPageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble((double)details.DetailToDetail.Count / (double)1)));
                SlidingEffect1.NextPageClientId = btnNext.ClientID;
                SlidingEffect1.PreviousPageClientId = btnPrevious.ClientID;

                if (Convert.ToBoolean(SessionHandler.GetItem("EnabledAjax")) != false)
                    SlidingEffect1.PagingWritenId = lblPaging.ClientID;

                btnNext.ImageUrl = "";
                SlidingEffect1.PagingContainerId = NavigationPanel.ID;

                if (Convert.ToBoolean(SessionHandler.GetItem("EnabledAjax")) == false)
                {
                    SlidingEffect1.IsPaging = true;
                    SlidingEffect1.PagingInImages = false;
                }
                SlidingEffect1.SelectedImageUrl = Convert.ToString(Application["images"]) + "box_active.png";
                SlidingEffect1.UnSelectedImageUrl = Convert.ToString(Application["images"]) + "box_inactive.png";

                btnNext.ImageUrl = Convert.ToString(Application["images"]) + "right_aero.gif";

                SlidingEffect1.ControlPath = "~/UserControl/NewWeekSlider.ascx";
            }
            else
            {
                NoNewsMessage.Visible = true;
            }
        }
        //catch (Exception ex)
        //{

        //}
    }

    void SlidingEffect1_itemDatabound(object sender, ListViewItemEventArgs e)
    {

        try
        {
            LogoDetailDetail info = new LogoDetailDetail();
            info = ((LogoDetailDetail)(((System.Web.UI.WebControls.ListViewDataItem)(e.Item)).DataItem));

            HtmlImage img = e.Item.FindControl("img1") as HtmlImage;
            bool bolImageUrl;
            bolImageUrl = true;
            if (img != null)
            {
                img.Attributes["dummySrc"] = info.FileName;
                img.Src = "";
                //img.Attributes.Add("role", "img");
            }


            string ClientId = "";
            if (Convert.ToString(SessionHandler.GetItem("CurrenPageHiden")) == "")
            {
                HtmlInputHidden htmlInputHidden = SlidingEffect1.FindControl("CurrentState") as HtmlInputHidden;
                ClientId = htmlInputHidden.ClientID;

            }
            else
            {
                ClientId = Convert.ToString(SessionHandler.GetItem("CurrenPageHiden"));
            }

        }
        catch (Exception ex)
        {

        }
    }
}
